package com.asiainfo.cms.system.controller.system;

import com.asiainfo.cms.common.result.Result;
import com.asiainfo.cms.common.vo.LoginUser;
import com.asiainfo.cms.system.service.ISysConfigService;
import com.asiainfo.cms.system.service.ISysUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController {
    @Autowired
    private ISysUserService registerService;

    @Autowired
    private ISysConfigService configService;

    @PostMapping("/register")
    public Result register(@RequestBody LoginUser user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return Result.error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? Result.ok() : Result.error(msg);
    }
}
